const app = getApp();
Page({

  data: {
    who: ''
  },

  onLoad: function (e) {
    var that = this;
    setTimeout(function () {
      that.wel()
    }, 2000);
  },
  wel: function (e) {
    var that = this;
    var userid = wx.getStorageSync('openid')
    console.log(userid)
    wx.request({
      url: app.globalData.ServerUrl + 'wel.php',
      data: {
        userid: userid
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      dataType: 'json',
      responseType: 'text',
      success: function (res) {
        console.log(res.data)

        if (res.data != null) {
          that.setData({
            who: res.data[0].who
          })
          console.log(that.data.who)
          if (that.data.who == "学生") {
            wx.reLaunch({
              url: '../home/home/home?who=0'
            })
            console.log('学生身份：' + that.data.who)
          } else if (that.data.who == "教师") {
            wx.reLaunch({
              url: '../home/home/home?who=1'
            })
            console.log('教师身份：' + res.data[0].who)
          }

        } else {
          wx.reLaunch({
            url: '../who/who',
          })
          console.log("前往身份信息注册")
        }


      },
      fail: function (res) {},
      complete: function (res) {},
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  //监听页面显示
  onShow: function () {

  },
  /**2秒后自动跳转 */

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})